fix: ensure RecordCopyPolicy and RecordInstantiationPolicy set for all embeddable records - #2799
Closed
hantsy wants to merge 2 commits into
Closed
fix: ensure RecordCopyPolicy and RecordInstantiationPolicy set for all embeddable records#2799hantsy wants to merge 2 commits into
hantsy wants to merge 2 commits into
Conversation
Contributor
Author
|
I used Claude Code to analyze the issue and create this PR and try to resolve #2656 |
hantsy
force-pushed
the
fix/record-embeddedid-support-master
branch
from
August 1, 2026 00:54
5015563 to
b3b6a9f
Compare
hantsy
force-pushed
the
fix/record-embeddedid-support-master
branch
2 times, most recently
from
August 16, 2026 03:13
bc45ec2 to
c72e643
Compare
Records are immutable value types, so EclipseLink must construct and copy them through their canonical constructor and record components rather than through no-arg construction and field reflection. - Set RecordCopyPolicy and RecordInstantiationPolicy for record descriptors regardless of field or method access. - Build record primary key classes via their canonical constructor in CMPPolicy.createPrimaryKeyInstance() (fixes record @EmbeddedId/@IdClass). - Replace record aggregates with a clone instead of merging field-by-field in AggregateMapping.mergeChangesIntoObject(). Co-Authored-By: Claude <noreply@anthropic.com>
hantsy
force-pushed
the
fix/record-embeddedid-support-master
branch
from
August 16, 2026 05:05
c72e643 to
5fc024d
Compare
Contributor
Author
|
Superseded — this has been split into three focused PRs (one fix + test each):
Closing this in favor of the three. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
@
Fixes #2656 —
IllegalAccessException: Can not set final fieldwhen using Java records as@Embeddablewith@EmbeddedIdor@Embedded.Root Cause
ClassDescriptor.initialize()wraps the record detection (lines 3984–4003) in aif (!isMethodAccess)guard. For embeddable records whose mappings use method access (the default, since record accessor methods likeid()are methods),RecordCopyPolicyandRecordInstantiationPolicywere never initialized.Without
RecordCopyPolicy, the UOW working copy clone path callsPersistenceEntityCopyPolicy._persistence_shallow_clone()which usesObject.clone()— this fails on records because their fields arefinal.Without
RecordInstantiationPolicy,buildNewInstance()falls back to the default no-arg-constructor path, which also fails because records have no no-arg constructor.Fix
Move the record-specific policy initialization outside the
!isMethodAccessguard. Records always needRecordCopyPolicyandRecordInstantiationPolicyregardless of access type, because their fields are alwaysfinal.Additional change
The empty
catch (Exception ignore)was masking failures during instantiation policy setup. Added a comment explaining the intent.Test
Added
TestRecordEmbeddablewith:RecordId(UUID id)—@Embeddablerecord used as@EmbeddedIdRecordValue(String description, int amount)—@Embeddablerecord used as@EmbeddedRecordEntity— entity exercising bothtestPersistAndFind— persist → clear → find → verifytestMerge— persist → clear → merge with updated valuesWithout the fix, both tests throw
IllegalAccessExceptionduring persist or merge.@